package com.spider.spiderorderadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spider.spiderorderadmin.entity.model.UserRole;
import com.spider.spiderorderadmin.entity.param.SystemRoleQueryParam;
import com.spider.spiderorderadmin.mapper.UserRoleMapper;
import com.spider.spiderorderadmin.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author xiong.bo
 * @version 1.0
 * @date 2024/6/19 10:27 下午
 */

@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole>
        implements UserRoleService {


    @Override
    public Integer deleteByUserId(Long userId) {
        LambdaQueryWrapper<UserRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRole::getUserId, userId);
        return this.baseMapper.delete(queryWrapper);
    }

    @Override
    public List<UserRole> selectByUserId(Long userId) {
        LambdaQueryWrapper<UserRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRole::getUserId, userId);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public Page<UserRole> selectByRoleId(SystemRoleQueryParam queryParam) {
        LambdaQueryWrapper<UserRole> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserRole::getRoleId, queryParam.getRoleId());
        return this.baseMapper.selectPage(queryParam.buildPage(), queryWrapper);
    }


}
